package com.bango.nokia.java;

class BangoSymbianDeviceDetails
{
	private static String _deviceMake = "";
	private static String _deviceModel = "";
	private static String _modelVersion = "";
	private static String _firmwareVersion = "";
	private static String _platformName = "";
	private static String _platformVersion = "";
	private static String _javaRuntimeVersion = "";
	private static String _configuration = "";
	private static String _profile = "";

	static String DeviceMake()
	{
		return _deviceMake;
	}

	static String DeviceModel()
	{
		return _deviceModel;
	}

	static String ModelVersion()
	{
		return _modelVersion;
	}

	static String DeviceModelAndVersion()
	{
		if (_modelVersion != "")
		{
			return _deviceModel + "-" + _modelVersion;
		}
		else
		{
			return _deviceModel;
		}
	}

	static String FirmwareVersion()
	{
		return _firmwareVersion;
	}

	static String PlatformName()
	{
		return _platformName;
	}

	static String PlatformVersion()
	{
		return _platformVersion;
	}

	static String JavaRuntimeVersion()
	{
		return _javaRuntimeVersion;
	}

	static String Profile()
	{
		return _profile;
	}

	static String Configuration()
	{
		return _configuration;
	}

	static
	{
		String deviceMake = "";
		String deviceModel = "";
		String modelVersion = "";
		String firmwareVersion = "";
		String platformName = "";
		String platformVersion = "";
		String javaRuntimeVersion = "";

		String tstr = BangoStatic.GetProperty(BangoConstants.ACCESS_DEVICE_PROPERTIES);
		String tstr2;
		String tstr3;
		String[] platformProperties;
		String modelDetails = "";
		String platformDetails = "";
		int tint;
		int tint2;

		tint = tstr.indexOf("sw_platform");

		// S40s
		if (tint == -1)
		{
			modelDetails = tstr;
		}
		// S60s
		else
		{
			modelDetails = tstr.substring(0, tint - 1);
			platformDetails = tstr.substring(tint);
		}

		if (modelDetails != "")
		{
			tstr = modelDetails;
			tint = tstr.indexOf("/");
			// With firmware version
			if ((tint != -1) && (tstr.length() - 1 > tint))
			{
				firmwareVersion = tstr.substring(tint + 1).trim();
				tstr = tstr.substring(0, tint).trim();
			}

			tint = tstr.indexOf("-");
			// With model version
			if ((tint != -1) && (tstr.length() - 1 > tint))
			{
				modelVersion = tstr.substring(tint + 1).trim();
				tstr = tstr.substring(0, tint).trim();
			}

			// As the Java Symbian API does not provide a way of reliably
			// determining the device make,
			// check if it is a Nokia, and only set device makes for Nokia.
			if (tstr.toLowerCase().startsWith("nokia"))
			{
				deviceMake = "Nokia";
				deviceModel = tstr.substring(5);
			}
			else
			{
				deviceModel = tstr;
			}
		}

		if (platformDetails != "")
		{
			platformProperties = BangoStatic.SplitString(platformDetails, ";");

			for (tint = 0; tint < platformProperties.length; tint++)
			{
				tstr = platformProperties[tint].trim();

				tint2 = tstr.indexOf("=");

				if ((tint2 != -1) && (tstr.length() - 1 > tint2))
				{
					tstr2 = tstr.substring(0, tint2).trim();
					tstr3 = tstr.substring(tint2 + 1).trim();
					if (tstr2.equalsIgnoreCase("sw_platform"))
					{
						if (tstr3.equalsIgnoreCase("s60"))
						{
							platformName = "Series60";
						}
						else
						{
							platformName = tstr3;
						}
					}
					if (tstr2.equalsIgnoreCase("sw_platform_version"))
					{
						platformVersion = tstr3;
					}
					if (tstr2.equalsIgnoreCase("java_build_version"))
					{
						javaRuntimeVersion = tstr3;
					}
				}
			}
		}

		_deviceMake = deviceMake;
		_deviceModel = deviceModel;
		_modelVersion = modelVersion;
		_firmwareVersion = firmwareVersion;
		_platformName = platformName;
		_platformVersion = platformVersion;
		_javaRuntimeVersion = javaRuntimeVersion;
		_profile = BangoStatic.GetProperty(BangoConstants.ACCESS_DEVICE_PROFILE);
		_configuration = BangoStatic.GetProperty(BangoConstants.ACCESS_DEVICE_CONFIGURATION);

	}

}
